package com.bruce.demo2.patterns.demo2.structural.demo12.flyweight.demo1;

/**
 * @PROJECT_NAME: design_patterns
 * @DESCRIPTION: 测试类
 * @AUTHOR: CNBruceLee
 * @DATE: 2021/8/2 6:54
 */
public class Test {

    @org.junit.Test
    public void test() {
        //1、工厂方法获取工厂实例
        BoxFactory factory = BoxFactory.getInstance();
        //2、获取共享的角色
        AbstractBox Ibox = factory.getShape("I");
        Ibox.display("灰色");

        AbstractBox Lbox = factory.getShape("L");
        Lbox.display("蓝色");

        AbstractBox Obox1 = factory.getShape("O");
        Obox1.display("白色");

        AbstractBox Obox2 = factory.getShape("O");
        Obox2.display("橙色");

        System.out.println("两次获取到的O对象是否是同一个对象：" + (Obox1 == Obox2));
    }
}
